Fix panic on text align with unicode#404
Merged
jedib0t merged 1 commit intojedib0t:mainfrom Apr 21, 2026
Merged
Conversation
|
Coverage Report for CI Build 24737841796Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Owner
|
Awesome! Thanks! 🙏 |
Owner
|
@edznux-dd Here is a tag you can use: https://github.com/jedib0t/go-pretty/releases/tag/v6.7.10 |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Proposed Changes
Hey, small PR after doing some cleanup :)
It's possible to panic on
text.justifyTextwithstrings: negative Repeat countwhen a cell's display width (CJK-aware, viago-runewidth) exceedsmaxLength.The source of the issue is that
numSpacesNeeded = maxLength - textLength + spacesgoes negative, then is passed tostrings.Repeat, which does panic on negative see here)I've made this fix: early-return the text unchanged when
numSpacesNeeded < 0(consistent with howAlignCenterhandles the overflow case), as it seemed the best way to fix.If you want a small and easy reproducer that you can run:
I also added a small fuzz test: it won't really run as a fuzz test in your CI as far as I can tell, but should allow you to find similar issues in the future if you run it manually. (Doing the CI setup change to run
go test -fuzzis outside of the scope of this PR haha)